﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WebMvc.App.Web.Default.postgresqlTrans
{
    public class updateAction  : Controller
	{
		public updateAction(System.IO.TextWriter tw):base(tw){}
		public updateAction(string fileName) : base(fileName) {}
		public updateAction(HttpContext context):base(context){}
		public updateAction(Microsoft.Owin.IOwinContext context):base(context){}
        public void update(string name,string pwd)
        {
            var con = new Npgsql.NpgsqlConnection(NFinal.Config.ConfigurationManager.ConnectionStrings["PostgreSql"].ConnectionString);
			con.Open();
            var trans = con.BeginTransaction();
            int count = 0;
            try
            {
                #region	var count; 更新表,并返回受影响行数
			var __update_count_command__ = new Npgsql.NpgsqlCommand("update users set name=@name,pwd=@pwd where id=1;", con);
			__update_count_command__.Transaction=trans;
			var __update_count_parameters__=new Npgsql.NpgsqlParameter[2];
					__update_count_parameters__[0] = new Npgsql.NpgsqlParameter("@name",NpgsqlTypes.NpgsqlDbType.Text);
					__update_count_parameters__[0].Value = name;
					__update_count_parameters__[1] = new Npgsql.NpgsqlParameter("@pwd",NpgsqlTypes.NpgsqlDbType.Text);
					__update_count_parameters__[1].Value = pwd;
			__update_count_command__.Parameters.AddRange(__update_count_parameters__);
				count = __update_count_command__.ExecuteNonQuery();
			__update_count_command__.Dispose();
			#endregion
			
                trans.Commit();
            }
            catch
            {
                trans.Rollback();
            }
            con.Close();
            Write(count);
        }
        
        
        
        
        
        
        
        
    }
}